
package com.xwli.jdk8new.lambda.test;

import com.xwli.jdk8new.lambda.domain.Person;
import com.xwli.jdk8new.lambda.service.UserService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @program: springcloud
 * @description: 有参有返回结果的案例
 * @author: xwli
 * @create: 2022-05-05 16:47
 **/
public class LambdaDemo04 {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();
        personList.add(new Person("张三",19,175));
        personList.add(new Person("李四",33,170));
        personList.add(new Person("小美",18,162));
        personList.add(new Person("小明",23,171));
        // Lambda标准写法
        Collections.sort(personList,(Person o1,Person o2)->{
            return o1.getHeight() - o2.getHeight();
        });
        for (Person person : personList) {
            System.out.println(person);
        }
        System.out.println("Lambda省略写法");
        // Lambda标准写法
        Collections.sort(personList,(o1,o2)->o1.getAge() - o2.getAge());
        for (Person person : personList) {
            System.out.println(person);
        }
    }

}
